
#include "Player.h"
#include "../ScriptApi.h"

namespace GTA
{

#pragma region constructor
	Player::Player()
	{
		PlayerId = Scripting::GetPlayerId(); 
		Base = Scripting::ConvertIntToPlayerIndex(PlayerId);
	}

	Player::Player(Scripting::Player base)
	{
		_player = base;
	}
#pragma endregion

#pragma region base

	Scripting::Player Player::Base::get()
	{

		return _player;
   }

	void Player::Base::set(Scripting::Player pl)
	{
		_player = pl;
   }

	GTA::Ped^ Player::GetPlayerPed()
	{

		Scripting::Ped ped;
		pin_ptr<Scripting::Ped> pPed = &ped;
		Scripting::GetPlayerChar(Base, pPed);
		return gcnew GTA::Ped(ped);
	};
#pragma endregion Base, GetPlayerPed()

#pragma region Properties
	GTA::Vector3^ Player::Coordinates::get()
	{
		float x,y,z;
		pin_ptr<float> pX = &x;
		pin_ptr<float> pY = &y;
		pin_ptr<float> pZ = &z;
		Scripting::GetCharCoordinates(GetPlayerPed()->Base,pX,pY,pZ);
		GTA::Vector3^ pos = gcnew GTA::Vector3(x,y,z);
		
		return pos;
	}
	void Player::Coordinates::set(GTA::Vector3^ pos)
	{
		Scripting::SetCharCoordinates(GetPlayerPed()->Base,pos->X,pos->Y,pos->Z);
	}

	f32 Player::Heading::get()
	{
		float heading;
		pin_ptr<float> pheading = &heading;
		Scripting::GetCharHeading(GetPlayerPed()->Base,pheading);
		return heading;
	}
	void Player::Heading::set(f32 heading)
	{
		Scripting::SetCharHeading(GetPlayerPed()->Base,heading);
	}

	GTA::eModel Player::Model::get()
	{
		GTA::eModel model;
		pin_ptr<GTA::eModel> pmodel = &model;
		Scripting::GetCharModel(GetPlayerPed()->Base,(Scripting::eModel*)pmodel);
		return model;
	}
	void Player::Model::set(GTA::eModel model)
	{
		Scripting::ChangePlayerModel(Base,(Scripting::eModel)model);
	}

	u32 Player::Health::get()
	{
		u32 health;
		pin_ptr<u32> phealth = &health;
		Scripting::GetCharHealth(GetPlayerPed()->Base,phealth);
		return health;
	}
	void Player::Health::set(u32 health)
	{
		Scripting::SetCharHealth(GetPlayerPed()->Base,health);
	}
#pragma endregion Coordinates, Heading, Model, Health

#pragma region Methods

	GTA::Vector3^ Player::GetAimCoordinates(float distance)
	{
		return World::GetAimCoordinates(distance);
	}

#pragma endregion

};